package com.quan.xczs.web.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.quan.base.common.base.web.support.BaseResult;
import com.quan.base.common.base.web.support.controller.BaseController;
import com.quan.base.common.utils.Paginator;
import com.quan.upms.annotation.RequiresPermissions;
import com.quan.xczs.rpc.api.XczsGoodsService;
import com.quan.xczs.rpc.model.XczsGoods;

@RestController
@RequestMapping(value = "/api/xczs/goods")
public class XczsGoodsController extends BaseController {

	@Autowired
	private XczsGoodsService xczsGoodsService;
	
	@RequiresPermissions(value="xczs:goods:add", description="添加学车招生平台商品")
	@PostMapping(value = "/add")
	public Object add(@Valid @RequestBody XczsGoods entity, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
            return BaseResult.failure(bindingResult.getFieldError().getDefaultMessage()) ;
        }
		this.xczsGoodsService.insertSelective(entity);

		return BaseResult.ok();
	}

	@RequiresPermissions(value="xczs:goods:delete", description="删除学车招生平台商品")
	@GetMapping(value = "/delete/{id}")
	public Object delete(@PathVariable Integer id) {
		this.xczsGoodsService.delete(id);
		return BaseResult.ok();
	}
	
	@RequiresPermissions(value="xczs:goods:delete", description="删除学车招生平台商品")
	@GetMapping(value = "/deleteBatch")
	public Object deleteBatch(String ids) {
		this.xczsGoodsService.deleteByIds(ids) ;
		return BaseResult.ok();
	}

	@RequiresPermissions(value="xczs:goods:update", description="修改学车招生平台商品")
	@PostMapping(value = "/update")
	public Object update(@Valid @RequestBody XczsGoods entity, BindingResult bindingResult) {
		if (bindingResult.hasErrors()) {
            return BaseResult.failure(bindingResult.getFieldError().getDefaultMessage()) ;
        }
		this.xczsGoodsService.update(entity);
		return BaseResult.ok();
	}

	@RequiresPermissions(value="xczs:goods:detail", description="查询学车招生平台商品详情")
	@GetMapping(value = "/get/{id}")
	public Object list(@PathVariable Integer id) {
		return this.xczsGoodsService.selectById(id);
	}
	
	@RequiresPermissions(value="xczs:goods:list", description="查询学车招生平台商品")
	@GetMapping(value = "/list")
	public Object list(XczsGoods entity) {
		return this.xczsGoodsService.selectPage(new Paginator(request), entity) ;
	}
}
